package com.dnjn.happiness.survey.api.factory;

import com.dnjn.happiness.common.core.domain.R;
import com.dnjn.happiness.survey.api.RemoteSurveyRecordService;
import com.dnjn.happiness.survey.api.RemoteSurveyService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class RemoteSurveyRecordFallbackFactory implements FallbackFactory<RemoteSurveyRecordService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteSurveyRecordFallbackFactory.class);

    @Override
    public RemoteSurveyRecordService create(Throwable throwable) {
        log.error("调用surveyRecord服务失败：" + throwable.getMessage());
        return new RemoteSurveyRecordService() {
            @Override
            public R<Integer> getSurveyRecordNotJoin(Long userId,String time, String source) {
                return R.fail("获取surveyRecord失败: {}" + throwable.getMessage());
            }

            @Override
            public R<Double> selectGradeByX(Long userId, String time, double recordScore, double x, double y, String source) {
                return R.fail("获取surveyRecord失败: {}" + throwable.getMessage());
            }
        };
    }
}
